package com.bocai.dahuatech.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bocai.dahuatech.Bean.OrderListBean;
import com.bocai.dahuatech.R;
import com.bumptech.glide.Glide;

import java.util.List;

public class MyOrderAdapter extends BaseAdapter {
    private Context context;
    List<OrderListBean.ContentEntity.ProductListEntity> datas;
    public  MyOrderAdapter(Context context,List<OrderListBean.ContentEntity.ProductListEntity> datas){
        this.context=context;
        this.datas=datas;
    }
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            viewHolder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.myorder_item,null);
            viewHolder.ivPic= (ImageView) convertView.findViewById(R.id.iv_order_pic);
            viewHolder.tvModel= (TextView) convertView.findViewById(R.id.tv_order_model);
            viewHolder.tvName= (TextView) convertView.findViewById(R.id.tv_order_name);
            viewHolder.tvPrice= (TextView) convertView.findViewById(R.id.tv_order_price);
            viewHolder.tvNum= (TextView) convertView.findViewById(R.id.tv_order_num);

            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.tvModel.setText(datas.get(position).getFOutModel());
        viewHolder.tvName.setText(datas.get(position).getFItemName());
        viewHolder.tvPrice.setText(context.getResources().getString(R.string.money) +datas.get(position).getFStandPrice());
        viewHolder.tvNum.setText(context.getResources().getString(R.string.x)+datas.get(position).getFAQty());
        Glide.with(context).load(datas.get(position).getFImgSrc())
//                .error(R.mipmap.product_photo_defalt)
//                .placeholder(R.mipmap.product_photo_defalt)
                .into(viewHolder.ivPic);
        return convertView;
    }
    class ViewHolder{
        TextView tvModel,tvName,tvPrice,tvNum;
        ImageView ivPic;
    }
}
